package com.longxi.tianjintianbao.ui.presenter.rectification;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.adapter.RectificationListPagerAdapter;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.base.BasePresenter;
import com.longxi.tianjintianbao.ui.fragment.rectification.RectificationListFragment;
import com.longxi.tianjintianbao.ui.view.rectification.IRectificationListAtView;
import com.longxi.tianjintianbao.utils.MyUtils;

import java.util.ArrayList;
import java.util.List;

public class RectificationListAtPresenter extends BasePresenter<IRectificationListAtView> {

    private RectificationListPagerAdapter rectificationListPagerAdapter;

    private void initVariable() {
        mCategoryList = new ArrayList<>();
        mCategoryList.add("未完成");
        mCategoryList.add("已完成");
    }

    //tab 标签页
    private List<String> mCategoryList;

    public List<String> getCategoryList() {
        if (mCategoryList == null) {
            mCategoryList = new ArrayList<>();
        }
        return mCategoryList;
    }

    public RectificationListAtPresenter(BaseActivity context) {
        super(context);
    }

    public void setBar() {
        mContext.setTitle("工作整改");
        mContext.setTvLeft(MyUtils.getString(R.string.home));
        initVariable();
    }

    public void initViewPager(){
        rectificationListPagerAdapter = new RectificationListPagerAdapter(mContext.getSupportFragmentManager(), getCategoryList());
        getView().getViewPager().setAdapter(rectificationListPagerAdapter);
        getView().getViewPager().setOffscreenPageLimit(getCategoryList().size() - 1);
        getView().getTabLayout().setTabSpaceEqual(true);
        getView().getTabLayout().setViewPager(getView().getViewPager());
    }

    public void refreshFragmentUi() {
        RectificationListFragment rectificationListFragment = (RectificationListFragment) rectificationListPagerAdapter.getCurrentFragment();
        rectificationListFragment.refreshReceiptList();
    }

    @Override
    public void detachView() {
        super.detachView();
        this.rectificationListPagerAdapter = null;
    }
}
